package com.blb.community.Utils;

import com.blb.community.pojo.fourMenu.FourMenu;

import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

/**
 * 集合转树形结构
 */
public class ListByStreamToTree {
    public static List<FourMenu> FourMenuTree(List<FourMenu> treeList) {
        Map<Long, List<FourMenu>> groupMap = treeList.stream().collect(Collectors.groupingBy(FourMenu::getParentId));
        treeList.forEach(fourMenu-> {
            fourMenu.setChildren(groupMap.get(fourMenu.getValue()));
        });
        List<FourMenu> collect = treeList.stream().filter(fourMenu-> fourMenu.getParentId().equals(0L)).collect(Collectors.toList());
        return collect;
    }
    
}
